home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / hard / hack / i2clib40.lha / i2clib40 / Intro / ReadMe.doc < prev    next >
Text File  |  1998-09-13  |  14KB  |  336 lines

  1. document i2c.library
  2.  
  3.                              i2c.library
  4.                        A Postcard-Ware Library
  5.  
  6.       © Copyright 1993-96 by GizmoSoft Productions / Brian Ipsen
  7.                  © Copyright 1997-98 by Wilhelm Nöker
  8.  
  9.                          All rights reserved.
  10.  
  11.  
  12.  
  13. 0. Disclaimer
  14. =============
  15.  
  16. The authors neither assume nor accept any responsibility for the use
  17. or misuse of this library, code or connected hardware.
  18.  
  19. The authors will not be liable for any damage arising from the failure
  20. of this library to perform as described, or any destruction of other
  21. programs or data residing on a system attempting to use the library
  22. functions. The user of this program uses it at his or her own risk.
  23.  
  24. No guarantee of any kind is given that the library described in 
  25. this document is 100% reliable. You are using this material on your
  26. own risk.
  27.  
  28.  
  29.  
  30. 1. About the I2C bus
  31. ====================
  32.  
  33.  
  34. 1.1. History and background
  35. ---------------------------
  36.  
  37. An increasing number of complex integrated circuits, ranging from
  38. real-time clocks to frequency synthesizers, is provided with an I2C
  39. bus interface. Not surprisingly, the I2C bus is found in a wide
  40. variety of electronic equipment, including telephones, car radios,
  41. television sets and video recorders.
  42.  
  43. The acronym I2C stands for Inter-IC Communication, and the network was
  44. developed by Philips to reduce the number of connections between
  45. integrated circuits. This proved feasible in pratice mainly because
  46. many ICs have a large number of pins that carry information that is
  47. not time-critical and, therefore, suitable for conveying via a
  48. relatively slow serial bus with fewer connections than would be
  49. required for a high-speed parallel interface. The implementation of
  50. the I2C bus on a real-time clock chip, for instance, may reduce the
  51. number of pins from 40 to as few as 8. This results in a much simpler
  52. PCB design with all benefits of lower production cost and smaller
  53. risks of faults developing in equipment. However, a number of
  54. connections, including those for the supply voltage, for clock
  55. signals, etc., can not be replaced by a serial communication protocol.
  56. It will be clear that these connections remain necessary as before.
  57.  
  58. All ICs that use the I2C bus are in principle connected to two lines
  59. (check figure 1). A central bus interconnects two microcontrollers, a
  60. memory, a gate array and an LCD driver.
  61.  
  62. In spite of their wide diversity as regards function and appli-
  63. cation, all I2C-compatible integrated circuits have one common
  64. feature: all control commands and data are conveyed via a serial bus,
  65. according a predefined communication protocol. The serial bus takes
  66. the form of three lines: ground, clock (SCL) and data (SDA).
  67.  
  68. Normally, any I2C configuration has at least one master (an IC capable
  69. of initiating the data exchange processes and generating a master
  70. clock signal) and one or more slaves (ICs that do the actual work). A
  71. master can be a microprocessor such as an 8048, an 8051 or a 68000,
  72. which are available in special versions with a built-in I2C bus
  73. interface. Two I/O port lines of the microprocessor are used as SDA
  74. and SCL lines. Together with the ground line, this implements an I2C
  75. bus which allows serial communication between 'bused' devices at a
  76. rate of up to 100 kbit per second.
  77.  
  78. It is also possible to emulate a I2C bus master on a computer with
  79. this library and some hardware. This requires 3 lines from a port,
  80. which is for example (in case you're using the parallel interface from
  81. Jan Leuverink's TeleText package) D2, SEL and POUT.
  82.  
  83.  
  84. 1.2. Control programs
  85. ---------------------
  86.  
  87. The two communication lines, SDA and SCL, are connected to open-drain
  88. or open-collector outputs, and have one, common, pullup-resistor
  89. (check figure 2). This arrangement is called a wired AND-structure.
  90. Adding or removing one or more I2C components on the bus therefore
  91. does not affect the operation of already connected ICs, nor does it
  92. affect the software that runs on the system. In fact, the software is
  93. capable of automatic detection of the hardware configuration. This
  94. allows programs to be written for complex systems that do not provide
  95. certain features unless the relevant chips are connected to the bus.
  96. The absence of these chips is automatically detected by the master
  97. controller which interrogates certain addresses.
  98.  
  99. Existing software may be extended with subroutines written for add-on
  100. ICs without affecting the operation of the ICs already installed. This
  101. allows existing control programs to be used for a long time without
  102. the need of a completely new version every time the hardware is
  103. modified. This high level of compability is achieved by virtue of the
  104. fixed adresses of the ICs on the I2C bus.
  105.  
  106.  
  107. 1.3. Two lines
  108. --------------
  109.  
  110. Both SDA and SCL are bidirectional lines, connected to a positive
  111. supply voltage via a pull-up resistor (see figure 2). When all output
  112. transistors of connected devices are off, the bus is free, and both
  113. lines are high. When an IC is ready to transmit a data block, it pulls
  114. SDA low to mark a start condition. From that moment, all other ICs
  115. 'know' that the bus is in use. Arbitration procedures come into effect
  116. should one or more ICs claim access to the bus simultaneously. When
  117. the start condition is recognized, the SDA line is available for
  118. carrying databits. The clock line, SCL, determines the validity of the
  119. data levels on the SDA line (check figure 3).
  120.  
  121. The start of any data exchange via the bus is marked by SDA going low
  122. while SCL is high, i.e., by a start condition (check figure 4). The
  123. level on the SDA line is read by all ICs on the bus during the
  124. positive part of the clock pulse. However, only the IC selected by the
  125. transmitted address-code responds to the information by actually
  126. loading the data and returning an acknowledge pulse. This pulse is
  127. generated by the addressed slave device by pulling the data line low
  128. for one clock period after the eight clock periods reserved for the
  129. databits (check figure 4).
  130.  
  131. When none of the ICs in the system responds to the transmitted data,
  132. the master does not receive an acknowledge pulse. This means that
  133. either the addressed slave is busy performing some real-time function,
  134. the address is wrong or there is no device that responds at that
  135. particular address. The bus is free again after the transmission of
  136. the last data bit. Both SCL and SDA revert to high, and the bus may be
  137. used to convey the next data block.
  138.  
  139. The function of the SCL line is to generate one clock pulse for every
  140. transmitted databit. Each master must generate its own SCL signal.
  141. Although the frequency of this signal is not fixed, certain minimum
  142. timing specifications must be preserved. In practice, the I2C bus
  143. allows a maximum data speed of about 100 Kbit/s.
  144.  
  145.  
  146. 1.4. Adressing
  147. --------------
  148.  
  149. Each IC on the I2C bus has its own, unique 7-bit address, which is
  150. determined by the manufacturer and hard-coded into the chip. The type
  151. PCF8583 real-time clock chip for example, is selected by sending
  152. binary code 101000x. The last bit is user-preset (x is 0 or 1) to
  153. allow two identical ICs to be used in parallel by tying their inputs
  154. to ground or the positive supply to set the address to 1010000 or
  155.  1010001 respectively. Similary, certain ADCs, DACs chips and memories
  156. may be hard-wired to map them at one of up to eight adresses in a
  157. cluster.
  158.  
  159. The data clock conveyed via the bus invariably consist of 8 bits. The
  160. bit that follows the address indicates the start of a read or write
  161. operation with the selected IC. Bit 8 is low for a write operation,
  162. and high for a read operation.
  163.  
  164.  
  165. 1.5. Applications
  166. -----------------
  167.  
  168. There is much more to the concept of the I2C bus than can be described
  169. here. The full specification of the system may be found in the I2C-bus
  170. Specifications by Philips Components. The I2C bus is relatively simple
  171. to implement on almost any microcomputer system that has at least one
  172. user port. If nessecery, external buffers may have to be added to make
  173. such a port bidirectional. Some microcomputers, including the Acorn
  174. Archimedes, even have an I2C interface a a standard feature.
  175. Developers of small stand-alone microprocessor systems may find the
  176. I2C version of the 8048, the PCF84C00T, a good